import { ref } from 'vue'
import { adapter, request } from '@/request'
import { calRenewalPriceByPost } from '@/core/api/order'
import type { RequestWrapper } from '@/core/interfaces/common'
import type { ComboPriceNameEnum } from '@/core/enums/name'

interface Params {
  orderId: number
  rechargeTime: ComboPriceNameEnum
}

interface RenewalPrice {
  assessRechargeMarketPriceMarket: number
  assessRechargePrice: number
}

export default function calRenewalPrice() {
  const service = adapter<RequestWrapper<RenewalPrice>>(request)
  const loading = ref(false)
  const response = ref<Partial<RenewalPrice>>({})

  const fetch = (data: Params) => {
    const { url, method } = calRenewalPriceByPost()
    loading.value = true

    return service({
      config: {
        url,
        method,
        data
      },
      callback: (res) => {
        response.value = res.data.data
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [response, fetch, loading] as const
}
